package com.eascs.admin.o2o.oaotodata.dao;

import org.springframework.stereotype.Repository;

import com.eascs.admin.common.dao.BaseO2oDao;
import com.eascs.admin.common.utils.StringUtils;
import com.eascs.admin.o2o.internal.util.BaseUtils;
import com.eascs.admin.o2o.oaotodata.form.AccLoanapplyForm;
import com.eascs.admin.o2o.zx.entity.O2oLoanUserEntityZx;
import com.eascs.admin.o2o.zx.vo.O2oZxUserVo;
import com.eascs.admin.oldO2olike.form.OldO2oLikeForm;
import com.eascs.app.dao.PageResult;
import com.eascs.app.dao.SqlPageQuery;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;

/**
* @author bao.pan 2016年12月25日 上午2:00:57
*/
@Repository
public class O2oComDataDao extends BaseO2oDao{
	protected final Logger logger = LoggerFactory.getLogger(getClass());
	public int findbyloanapplyno(){
		String sql="SELECT IFNULL( MAX(aa),0) as num from (select y.loanapply_no+0 as aa from o2o_loanapply y where data_source='2' ) t ";
		return this.findInteger(sql);
	}
	
	public PageResult<O2oZxUserVo> findZXByPage(OldO2oLikeForm oldO2oLikeForm) {
		SqlPageQuery<O2oZxUserVo> pageQuery = new SqlPageQuery<O2oZxUserVo>(O2oZxUserVo.class,oldO2oLikeForm.getPageSize() ,
				oldO2oLikeForm.getPageIndex() == null ? BaseUtils.PAGE_INDEX : oldO2oLikeForm.getPageIndex());
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT z.id as zxid,l.id as userzxid,z.bill_code as billcode,l.user_full_name as userfullname,l.document_no as documentno,l.zx_date as zxdate,l.zx_td_date as zxtddate  ");
		sql.append(" from o2o_loan_user_zx l,o2o_zx z where l.zx_no=z.id and z.zx_status='CLO' and l.zx_date is not null ");
		if (!StringUtils.isEmpty(oldO2oLikeForm.getBrandName())) {
			sql.append(" and user_full_name like ? ");
			pageQuery.addLikeParam(oldO2oLikeForm.getBrandName());
		}
		sql.append(" ORDER BY z.create_date DESC ");
		pageQuery.setQuerySql(sql.toString());
//		this.findDataWithPage(sqlPageQuery)
		return this.findDataWithPage(pageQuery);
	}
//	public PageResult<AccLoanapplyForm> findwfByPage1(AccLoanapplyForm accLoanapplyForm) {
//		logger.info("未放款有收费未退任务运行中，正在查询第[{}]页数据", accLoanapplyForm.getPageIndex());
//		
//		String querySql="";
//		SqlPageQuery<AccLoanapplyForm> sqlPageQuery = new SqlPageQuery<>(AccLoanapplyForm.class, accLoanapplyForm.getPageSize(),
//				accLoanapplyForm.getPageIndex(), querySql);
//		return this.findDataWithPage(sqlPageQuery);
//	}
}
